<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>setksmps</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="setctrl.html" title="setctrl" />
    <link rel="next" href="setrow.html" title="setrow" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">setksmps</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="setctrl.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="setrow.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="setksmps"></a>
      <div class="titlepage"></div>
      <a id="IndexSetksmps" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">setksmps</span>
        </h2>
        <p>setksmps — 
      Sets the local ksmps value in an instrument or user-defined opcode block
    </p>
      </div>
      <div class="refsect1">
        <a id="idp145612032"></a>
        <h2>Description</h2>
        <p>
      Sets the local ksmps value in an instrument or user-defined opcode block.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp145613312"></a>
        <h2>Syntax</h2>
        <pre class="synopsis"><span class="command"><strong>setksmps</strong></span> iksmps</pre>
      </div>
      <div class="refsect1">
        <a id="idp145689392"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>iksmps</em></span> -- sets the local ksmps value.
    </p>
        <p>
      If <span class="emphasis"><em>iksmps</em></span> is set to zero, the <span class="emphasis"><em>ksmps</em></span> of the caller instrument or opcode is used (this is the default behavior).
    </p>
        <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
          <table border="0" summary="Note: Note">
            <tr>
              <td rowspan="2" align="center" valign="top" width="25">
                <img alt="[Note]" src="images/note.png" />
              </td>
              <th align="left">Note</th>
            </tr>
            <tr>
              <td align="left" valign="top">
                <p>
        The local <span class="emphasis"><em>ksmps</em></span> is implemented by splitting up a control period into smaller sub-kperiods and setting up the instrument local ksmps to the new value. This also requires converting the rate of k-rate input and output arguments (input variables receive the same value in all sub-kperiods, while outputs are written only in the last one). It also means that you cannot use a local <a class="link" href="ksmps.html" title="ksmps"><em class="citetitle">ksmps</em></a> that is higher than the global <a class="link" href="ksmps.html" title="ksmps"><em class="citetitle">ksmps</em></a>.
      </p>
              </td>
            </tr>
          </table>
        </div>
        <div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
          <table border="0" summary="Warning: Warning about local ksmps">
            <tr>
              <td rowspan="2" align="center" valign="top" width="25">
                <img alt="[Warning]" src="images/warning.png" />
              </td>
              <th align="left">Warning about local ksmps</th>
            </tr>
            <tr>
              <td align="left" valign="top">
                <p>
        When the local <span class="emphasis"><em>ksmps</em></span> is not the same as the orchestra level <span class="emphasis"><em>ksmps</em></span> value (as specified in the orchestra header), global a-rate operations must be carefully coded to access the data in a vector according to the local ksmps. The audio rate bus channel opcodes (chnget/chnset) can be used freely, however, as they will do the necessary conversion between ksmp sizes.
      </p>
                <p>
        Other opcodes that require some care include:

        </p>
                <div class="itemizedlist">
                  <ul class="itemizedlist" style="list-style-type: disc; ">
                    <li class="listitem">
                      <p>any access to <span class="quote">“<span class="quote">ga</span>”</span> variables</p>
                    </li>
                    <li class="listitem">
                      <p>a-rate zak opcodes (<a class="link" href="zar.html" title="zar"><em class="citetitle">zar</em></a>, <a class="link" href="zaw.html" title="zaw"><em class="citetitle">zaw</em></a>, etc.)</p>
                    </li>
                    <li class="listitem">
                      <p><a class="link" href="tablera.html" title="tablera"><em class="citetitle">tablera</em></a> and <a class="link" href="tablewa.html" title="tablewa"><em class="citetitle">tablewa</em></a> (these two opcodes may in fact work, but caution is needed)</p>
                    </li>
                    <li class="listitem">
                      <p>  The <span class="emphasis"><em>in</em></span> and <span class="emphasis"><em>out</em></span> opcode family cannot be used in local-ksmps UDOs (these read from, and write to global a-rate buffers), but are safe in local-ksmps instruments</p>
                    </li>
                  </ul>
                </div>
                <p>
      </p>
                <p>
        In general, the local <span class="emphasis"><em>ksmps</em></span> should be used with care as it is an experimental feature. Though it works correctly in most cases.
      </p>
              </td>
            </tr>
          </table>
        </div>
        <p>
      The <span class="emphasis"><em>setksmps</em></span> statement can be used to set the local <a class="link" href="ksmps.html" title="ksmps"><em class="citetitle">ksmps</em></a> value of the instrument or user-defined opcode block. It has one i-time parameter specifying the new <span class="emphasis"><em>ksmps</em></span> value (which is left unchanged if zero is used). <span class="emphasis"><em>setksmps</em></span> should be used before any other opcodes (but allowed after <a class="link" href="xin.html" title="xin"><em class="citetitle">xin</em></a> in UDOs), otherwise unpredictable results may occur.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp145711472"></a>
        <h2>Performance</h2>
        <p>
      The syntax of a user-defined opcode block is as follows:

      </p>
        <pre class="programlisting">
<span class="oblock">opcode</span>  name, outtypes, intypes
xinarg1 [, xinarg2] [, xinarg3] ... [xinargN]  <span class="opc">xin</span>
[<span class="opc">setksmps</span>  iksmps]
... the rest of the instrument's code.
<span class="opc">xout</span>  xoutarg1 [, xoutarg2] [, xoutarg3] ... [xoutargN]
<span class="oblock">endop</span>
      </pre>
        <p>
    </p>
        <p>
      The new opcode can then be used with the usual syntax:

      </p>
        <div class="literallayout">
          <p><br />
[xinarg1] [, xinarg2] ... [xinargN]  name  [xoutarg1] [, xoutarg2] ... [xoutargN] [, iksmps]<br />
      </p>
        </div>
        <p>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp145718400"></a>
        <h2>Examples</h2>
        <p>
      See the example for the <a class="link" href="opcode.html" title="opcode"><em class="citetitle">opcode</em></a> opcode.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp145720592"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="endop.html" title="endop"><em class="citetitle">endop</em></a>, 
      <a class="link" href="opcode.html" title="opcode"><em class="citetitle">opcode</em></a>, 
      <a class="link" href="xin.html" title="xin"><em class="citetitle">xin</em></a>, 
      <a class="link" href="xout.html" title="xout"><em class="citetitle">xout</em></a>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp145725520"></a>
        <h2>Credits</h2>
        <p>Author: Istvan Varga, 2002; based on code by Matt J. Ingalls; Modified by V Lazzarini for Csound 6</p>
        <p>New in version 4.22</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="setctrl.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="setrow.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">setctrl </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> setrow</td>
        </tr>
      </table>
    </div>
  </body>
</html>
